package com.gzz.orchid.common.boot;

import com.gzz.orchid.common.boot.asynclock.DistributedLockHepler;
import com.gzz.orchid.common.boot.configuraction.RedisConfiguraction;
import com.gzz.orchid.common.boot.mybatis.dbraw.MyBatisRawHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Lazy;

/**
 * @author higmd
 */
@Slf4j
@Configuration
@Import(RedisConfiguraction.class)
public class GolbalConfiguraction {
    static {
        log.info("启动Boot自动配置。。。。。。。。。。。。。。。。。。。。。");
    }

    /**
     * 分布式锁
     */
    @Bean
    @ConditionalOnBean(name = "stringRedisTemplate")
    public DistributedLockHepler distributedLockHepler() {
        System.out.println("启用DistributedLockHepler分布式锁。。。。。。。。。。。。。。。。。。。。。");
        return new DistributedLockHepler();
    }

    /**
     * mybatis 原生操作
     */
    @Lazy
    @Bean
    //@ConditionalOnBean(name = "sqlSessionFactory")
    public MyBatisRawHelper myBatisRawHelper(SqlSessionFactory sqlSessionFactory) {
        System.out.println("启用mybatis 原生操作。。。。。。。。。。。。。。。。。。。。。");
        return new MyBatisRawHelper(sqlSessionFactory);
    }
}
